package edu.sdjzu.exam.service.rocketmq;


import edu.sdjzu.exam.domain.exam.ExamAnswer;
import edu.sdjzu.exam.dto.ExamAnswerSubmitDTO;
import edu.sdjzu.exam.mapper.exam.ExamAnswersMapper;
import edu.sdjzu.exam.service.exam.ExamAnswerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RocketMQMessageListener(topic = "exam-result-topic", consumerGroup = "exam-result-consumer-group")
public class ExamResultConsumer implements RocketMQListener<ExamAnswer> {
    private final ExamAnswersMapper examAnswersMapper;
    public ExamResultConsumer(ExamAnswersMapper examAnswersMapper) {
        this.examAnswersMapper = examAnswersMapper;
    }
    @Override
    public void onMessage(ExamAnswer examAnswer) {
        log.info("收到考试数据: {}", examAnswer);

        // TODO：保存到数据库

//        examAnswerService.(examAnswer);
        examAnswersMapper.insertExamAnswer(examAnswer);


    }


}
